<template>
  <div class="artclelists">
    <el-breadcrumb separator="/" el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>文章管理</el-breadcrumb-item>
      <el-breadcrumb-item>文章列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-table :data="postlist" border style="width: 100%">
      <el-table-column prop="title" label="标题" width="540"> </el-table-column>
      <el-table-column prop="user.nickname" label="作者"> </el-table-column>
      <el-table-column prop="type" label="类型" width="180"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <!-- <span class="demonstration">完整功能</span> -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[4, 6, 8, 10]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getartcle } from "../apis/artcle.js";
export default {
  data() {
    return {
      postlist: [],
      pageIndex: 1,
      pageSize: 4,
      // currentPage1: 5,
      // currentPage2: 5,
      // currentPage3: 5,
      currentPage4: 4,
      total: 0,
    };
  },
  methods: {
    init() {
      getartcle({ pageIndex: this.pageIndex, pageSize: this.pageSize })
        .then((res) => {
          // console.log(123);
          console.log(res);
          this.postlist = res.data.data;
          // console.log(this.postlist);
        })
        .catch((err) => console.log(err));
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageIndex = val;
      this.init();
    },
    handleEdit(row) {
      console.log(row);

      this.init();
    },
    handleDelete(row) {
      console.log(row);
    },
  },
  mounted() {
    getartcle({ pageIndex: this.pageIndex, pageSize: 10000 })
      .then((res) => {
        // console.log(123);
        console.log(res);
        this.total = res.data.data.length;
        console.log(this.total);
      })
      .catch((err) => console.log(err));
    this.init();
  },
};
// export default {
//   data() {
//     return {
//       postArtclelist: [],
//       pagelist: 1,
//     };
//   },
//   methods: {
//     handleEdit(row) {
//       console.log(row);
//       getartcle()
//         .then((res) => {
//           if (res.datastatusText === "ok") {
//             this.postArtclelist = res.data;
//           }
//           console.log(res);
//         })
//         .catch((err) => console.log(err));
//     },
//     handleDelete(row) {
//       console.log(row);
//     },
//   },
// };
</script>
<style lang='less' scoped>
</style>
